package com.app.bimo.module_accounts.mvp.ui.view;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;


import com.app.bimo.commonbusiness.view.recyclerview.HeadFootRecyclerView;
import com.app.bimo.module_accounts.R;
import com.app.bimo.module_accounts.mvp.model.entiy.TagData;

import java.util.ArrayList;
import java.util.List;

import androidx.recyclerview.widget.GridLayoutManager;


/**
 * 偏好设置搜索标签
 */
public class SearchTagPopView extends FrameLayout {
    private HeadFootRecyclerView listView;
    private UserPreferTagAdapter adapter;
    private TextView empty;
    private List<TagData> list = new ArrayList<>();

    public SearchTagPopView(Context context) {
        this(context, null);
    }

    public SearchTagPopView(final Context context, AttributeSet attrs) {
        super(context, attrs);
        View.inflate(context, R.layout.account_view_user_prefer_tag, this);
        listView = findViewById(R.id.list);
        empty = findViewById(R.id.empty);
        listView.setLayoutManager(new GridLayoutManager(context, 1));
        adapter = new UserPreferTagAdapter(list, context);
        listView.setAdapter(adapter);

    }


    public void setList(List<TagData> list) {
        if (list.size() > 0) {
            empty.setVisibility(GONE);
        } else {
            empty.setVisibility(VISIBLE);
        }
        this.list.clear();
        this.list.addAll(list);
        adapter.notifyDataSetChanged();
    }

    public void setTagChooseClick(TagChooseClick tagChooseClick) {
        adapter.setTagChooseClick(tagChooseClick);
    }

    public void setKey(String key) {
        adapter.setSearchString(key);
    }
}
